/*
 * Copyright 2010 EES GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.eesgmbh.gimv.samples.googlechartapi.client.data;

import java.util.Arrays;
import java.util.Date;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 *
 * Sample data for Google Charts
 *
 * @author Sascha Hagedorn - EES GmbH - s.hagedorn@ees-gmbh.de
 *
 */
@SuppressWarnings("deprecation")
public class SampleDataFactory {

	private static int[] dataSet1 = {256, 256, 255, 255, 255, 254, 254, 254, 253, 253, 253, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 252, 252, 252, 252, 252, 251, 251, 251, 251, 251, 251, 251, 250, 250, 251, 250, 251, 251, 252, 251, 251, 251, 251, 251, 252, 252, 252, 252, 252, 253, 253, 253, 252, 252, 252, 253, 253, 253, 252, 253, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 254, 253, 253, 253, 253, 253, 253, 253, 253, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 256, 256, 256, 256, 256, 256, 257, 256, 257, 257, 257, 258, 258, 258, 258, 259, 259, 259, 260, 260, 260, 261, 261, 262, 262, 263, 263, 263, 264, 265, 266, 267, 267, 268, 269, 270, 271, 272, 273, 273, 274, 275, 276, 277, 277, 278, 279, 279, 280, 281, 281, 282, 283, 283, 284, 284, 285, 285, 286, 287, 287, 288, 289, 290, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 304, 305, 306, 307, 309, 310, 311, 312, 314, 315, 316, 317, 318, 318, 319, 319, 319, 320, 321, 321, 322, 323, 323, 324, 325, 325, 326, 326, 327, 328, 328, 328, 329, 329, 329, 330, 330, 331, 331, 331, 332, 332, 333, 333, 334, 334, 334, 335, 335, 335, 335, 336, 336, 336, 336, 337, 337, 337, 338, 339, 339, 340, 340, 341, 342, 343, 343, 344, 345, 345, 346, 346, 347, 348, 348, 348, 349, 350, 350, 351, 351, 352, 353, 353, 354, 355, 356, 357, 358, 359, 360, 361, 361, 362, 363, 363, 364, 364, 365, 365, 365, 365, 366, 366, 367, 367, 367, 368, 368, 369, 369, 370, 370, 371, 371, 372, 373, 373, 373, 374, 374, 375, 375, 376, 376, 376, 377, 378, 377, 378, 379, 379, 380, 380, 381, 381, 382, 382, 383, 383, 384, 384, 384, 385, 385, 386, 387, 387, 388, 388, 388, 389, 389, 389, 389, 390, 390, 391, 392, 392, 393, 393, 394, 395, 395, 396, 397, 397, 398, 398, 399, 399, 399, 400, 401, 401, 402, 402, 403, 404, 405, 405, 406, 407, 407, 408, 408, 409, 410, 410, 411, 411, 412, 413, 413, 414, 415, 415, 416, 417, 417, 418, 419, 420, 420, 421, 421, 422, 423, 423, 424, 425, 425, 426, 426, 427, 427, 428, 428, 429, 429, 430, 431, 431, 431, 431, 431, 432, 432, 432, 432, 432, 432, 433, 434, 434, 434};
	private static int[] dataSet2 = {397, 396, 396, 395, 395, 394, 393, 393, 392, 391, 391, 390, 389, 389, 388, 388, 387, 387, 386, 386, 385, 385, 385, 384, 384, 384, 383, 382, 382, 382, 382, 382, 382, 381, 381, 381, 381, 381, 380, 379, 379, 378, 378, 377, 377, 376, 376, 375, 375, 374, 373, 373, 372, 371, 371, 370, 370, 369, 368, 367, 367, 366, 365, 365, 364, 363, 363, 362, 361, 361, 360, 360, 359, 358, 358, 357, 357, 356, 355, 355, 354, 353, 352, 352, 351, 351, 350, 349, 349, 349, 348, 348, 347, 347, 346, 345, 345, 344, 343, 343, 342, 342, 341, 340, 340, 339, 339, 339, 339, 338, 338, 338, 337, 337, 336, 335, 335, 334, 334, 334, 333, 333, 332, 332, 331, 331, 330, 330, 329, 329, 328, 328, 327, 327, 326, 326, 326, 325, 325, 324, 324, 323, 323, 323, 322, 321, 321, 320, 320, 319, 319, 318, 318, 317, 317, 317, 316, 316, 315, 315, 315, 315, 314, 314, 313, 313, 312, 311, 311, 310, 309, 308, 307, 306, 305, 304, 303, 303, 302, 301, 301, 300, 300, 299, 298, 298, 298, 297, 296, 296, 295, 295, 294, 293, 293, 292, 291, 290, 290, 289, 289, 288, 287, 287, 287, 286, 286, 286, 286, 285, 285, 285, 285, 284, 284, 284, 283, 283, 282, 282, 281, 281, 281, 280, 280, 279, 279, 279, 278, 278, 278, 277, 276, 276, 275, 275, 274, 273, 273, 272, 271, 271, 270, 269, 269, 269, 268, 268, 267, 266, 265, 264, 262, 261, 260, 259, 257, 256, 255, 254, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 240, 239, 238, 237, 237, 236, 235, 235, 234, 234, 233, 233, 232, 231, 231, 230, 229, 229, 228, 227, 227, 226, 225, 224, 223, 223, 222, 221, 220, 219, 218, 217, 217, 216, 215, 214, 213, 213, 213, 212, 212, 211, 211, 210, 210, 210, 209, 209, 209, 208, 208, 208, 208, 207, 207, 207, 207, 206, 206, 206, 206, 206, 206, 206, 206, 205, 205, 205, 205, 205, 205, 205, 205, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202, 202};
	private static int minValue;
	private static int maxValue;

	static{
		int[] data = join(dataSet1, dataSet2);
		Arrays.sort(data);
		minValue = data[0];
		maxValue = data[data.length - 1];
	}

	public static SortedMap<Date, Integer> getSampleData1() {
		return getSampleData(dataSet1);
	}

	public static SortedMap<Date, Integer> getSampleData2() {
		return getSampleData(dataSet2);
	}

	public static int getMaxValue() {
		return maxValue;
	}

	public static int getMinValue() {
		return minValue;
	}

	private static SortedMap<Date, Integer> getSampleData(int[] values) {
		SortedMap<Date, Integer> data = new TreeMap<Date, Integer>();
		Date sampleDate = new Date(110, 1, 3);

		for (int i = 0; i < values.length; i++) {

			data.put(sampleDate, values[i]);

			sampleDate = (Date) sampleDate.clone();
			sampleDate.setMinutes(sampleDate.getMinutes() + 60);
		}
		return data;
	}

	private static int[] join(int[]arrayA, int[]arrayB) {
		final int aLength = arrayA.length;
	    final int bLength = arrayB.length;

	    if (aLength == 0) {
	        return arrayB;
	    }

	    if (bLength == 0) {
	        return arrayA;
	    }

	    final int[] both = new int[aLength + bLength];
	    System.arraycopy(arrayA, 0, both, 0, aLength);
	    System.arraycopy(arrayB, 0, both, aLength, bLength);

	    return both;
	}

}
